const typesModel = require('../model/typesModel');

// 查询
module.exports.find = async function (searchObj, page) {
    let { current, pageSize } = page;
    // 根据查询条件获取总数
    let total = await typesModel.countDocuments(searchObj);
    // 根据查询条件获取具体数量的数据
    let data = await typesModel.find(searchObj)
        .limit(pageSize).skip((current - 1) * pageSize);
    return { current, pageSize, total, rows: data }
}

// 查所有
module.exports.findAll = async function () {
    return await typesModel.find();

}
// 增加
module.exports.create = async function (types) {
    return await typesModel.create(types);
}

// 删
module.exports.remove = async function (id) {
    return await typesModel.remove({ _id: id });
}

// 改通过id得数据
module.exports.findById = async function (id) {
    return await typesModel.findById({ _id: id });
}

// 修改
module.exports.update = async function (id, types) {
    return await typesModel.updateOne(id, types);
}
